﻿/***************************************************************************
 //* Foxit Software Inc.
 //* Copyright(C) 2005-2012, all rights reserved.
 //*
 //* The following code is copyrighted and contains proprietary information
 //* and trade secrets of Foxit Software Inc.                                                      *
 ***************************************************************************/

/**
 * 基础命令类
 */

define(function (require, exports, module) {
    var WebPDF = require('./WebPDF');
    var CEventManager = require('./EventManager');
    /**
     * Base Command class.
     * @class Base Command class.
     * @constructor
     * @param {WebPDF.ReaderApp} readerApp The App object.
     * @param {Object} commandDefinition Command defination.
     * @example var commandDefination = {
 	 *        state: true,
     *        name: 'CommandName',
     *        exec: function (data) {alert(CommandName);}
     *   }
     * @return {WebPDF.BaseCommand} A command object.
     * @ignore
     */
    WebPDF.BaseCommand = function (readerApp, commandDefinition) {
        //Command状态，true或者false;
        this.state = commandDefinition.state;
        this.name = commandDefinition.name;
        this.execFunc = commandDefinition.exec;
        var _self = this;

        /**
         * @description Get the name of the command.
         * @return The name of the command.
         */
        this.getName = function () {
            return _self.name;
        };

        /**
         * @description Execute the command.
         * @param {Object} data  The command parameters.
         */
        this.execute = function (data) {
            return _self.execFunc.call(this, readerApp, data);
        };

        /**
         * @description Get the state of a command.
         * @return {Object} The state of the command.
         */
        this.getState = function () {
            return _self.state;
        };

        /**
         * @description Set the state of a command.
         * @param {Object} newState  New state.
         */
        this.setState = function (newState) {
            this.state = newState;
            $(_self).trigger('StateChange.'+readerApp.getAppId(),{state: newState});
            return true;
        };
    };
    return WebPDF.BaseCommand;
});